<html>
<head><meta charset="utf-8"><title>libraryfying match checking? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html">libraryfying match checking?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241081458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241081458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241081458">(Jun 01 2021 at 22:02)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> you <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8717#issuecomment-851506836">pinged me</a> about the possibility of libraryfying match checking. I think this is quite feasible!</p>



<a name="241081515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241081515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241081515">(Jun 01 2021 at 22:03)</a>:</h4>
<p>exhaustiveness checking specifically is a very independent bit of code. It uses only Ty and a crate-local Pat enum</p>



<a name="241081547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241081547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241081547">(Jun 01 2021 at 22:03)</a>:</h4>
<p>AFAIK it also uses a single query, namely checking for type inhabitedness</p>



<a name="241081671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241081671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241081671">(Jun 01 2021 at 22:04)</a>:</h4>
<p>I know that there Ty is in the process of being librarified. Are there also plans to share the representation of patterns at all?</p>



<a name="241083948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241083948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241083948">(Jun 01 2021 at 22:31)</a>:</h4>
<p>What kind of knowledge does it require about <code>Ty</code>? Does it care about specific <code>TyKind</code>s at all?</p>



<a name="241087100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241087100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241087100">(Jun 01 2021 at 23:08)</a>:</h4>
<p>Yeah it pattern-matches on <code>TyKind</code>s a ton</p>



<a name="241087476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241087476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241087476">(Jun 01 2021 at 23:14)</a>:</h4>
<p>Ah I guess another tricky bit is constants. There's a pass that converts constants into the corresponding patterns and rust-analyzer might need that for completeness. But that taps into constant evaluation which sounds like a can of worms</p>



<a name="241121078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241121078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241121078">(Jun 02 2021 at 08:48)</a>:</h4>
<p>Seems like constant evaluation can be exctacted relatively easy, no? </p>
<p>Bascially, the match checking code can be parametrized over <code>eval</code> function</p>



<a name="241121168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241121168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241121168">(Jun 02 2021 at 08:49)</a>:</h4>
<p>They <code>TyKind</code> feels more worrisome to me. Can the pattern-matching be moved to the caller? Ie, if it already has an internal IR of patterns, can we reformulate the code such that it's the caller who lowers <code>Ty</code> to patterns?</p>



<a name="241124159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241124159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241124159">(Jun 02 2021 at 09:20)</a>:</h4>
<p>TyKinds don't get interpreted as patterns. They're pattern-matched throughout the code to make all sorts of decisions :/</p>



<a name="241124930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241124930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241124930">(Jun 02 2021 at 09:28)</a>:</h4>
<p>But pattern-matching TyKind should be fine once Ty is extracted to a shared library between rustc and chalk, right?</p>



<a name="241124947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241124947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241124947">(Jun 02 2021 at 09:28)</a>:</h4>
<p>Right!</p>



<a name="241124982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241124982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241124982">(Jun 02 2021 at 09:29)</a>:</h4>
<p>So I guess it's better to re-visit this topic once types are extracted...</p>



<a name="241125132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241125132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241125132">(Jun 02 2021 at 09:30)</a>:</h4>
<p>Cool, let's do that</p>



<a name="241125254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241125254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241125254">(Jun 02 2021 at 09:31)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> what's the way for me to educate myself about the shared types library? </p>
<p>I am curious about  bunch of things: do types carry identity? are they just values? how the memory management works? does "code changes over time" aspect of rust-analyzer affects the types?</p>



<a name="241125469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241125469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241125469">(Jun 02 2021 at 09:33)</a>:</h4>
<p>FWIW here's what chalk currently uses <a href="https://docs.rs/chalk-ir/0.68.0/chalk_ir/enum.TyKind.html">https://docs.rs/chalk-ir/0.68.0/chalk_ir/enum.TyKind.html</a> . Ty itself is parameterized over an interner</p>



<a name="241127558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241127558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241127558">(Jun 02 2021 at 09:54)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> I don't know many details either, there's a hackmd somewhere, but my understanding is that it's mostly supposed to look like chalk_ir</p>



<a name="241128318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241128318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241128318">(Jun 02 2021 at 10:03)</a>:</h4>
<p><a href="https://github.com/rust-lang/wg-traits/issues/16">https://github.com/rust-lang/wg-traits/issues/16</a> is a good place to start I guess</p>



<a name="241379866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241379866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dawer <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241379866">(Jun 03 2021 at 11:55)</a>:</h4>
<p>We could also consider fallible implementation instead of bugging out with panic <a href="https://github.com/rust-analyzer/rust-analyzer/pull/9105#discussion_r644656085">https://github.com/rust-analyzer/rust-analyzer/pull/9105#discussion_r644656085</a></p>



<a name="241380760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/241380760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#241380760">(Jun 03 2021 at 12:04)</a>:</h4>
<p>we do want to bug out in debug builds, for actual bugs. For librarification we could maybe just control it with a cargo feature</p>



<a name="242418257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/242418257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#242418257">(Jun 12 2021 at 00:45)</a>:</h4>
<p>What's the scope of what rust-analyzer needs?</p>



<a name="242447334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/libraryfying%20match%20checking%3F/near/242447334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/libraryfying.20match.20checking.3F.html#242447334">(Jun 12 2021 at 12:15)</a>:</h4>
<p>Eventually, we need <em>everything</em>, so the question is rather "what's the most natural scope to create a boundary between the libraries"</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>